package com.ljx.offer;

/**
 * @author 李捷禧
 * Date: 2023/3/13
 * ClassName: C_27
 */

public class C_27 {

    public TreeNode mirrorTree(TreeNode root) {
        /**
        方式一：利用两个递归

        if(root == null) return null;
        TreeNode treeLeft = mirrorTree(root.right);
        TreeNode treeRight = mirrorTree(root.left);
        root.right = treeRight;
        root.left = treeLeft;
        return root;
        */
        //-----------------------
        /**
        方式二：内存占用大？
         内存一样大小，并没有创建任何对象 {@link com.ljx.other.NewInstanceTest}
         */
        if(root == null) return null;
        TreeNode treeRight = root.left;
        root.left = mirrorTree(root.right);
        root.right = mirrorTree(treeRight);
        return root;
    }

   class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;
        TreeNode(int x) { val = x; }
        }
}
